package cn.yx.common.jpa.repository;

import cn.yx.common.jpa.service.SnowflakeService;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

/**
 * <p>Hibernate 雪花算法ID生成器</p>
 *
 * @author Wgssmart
 */
public class SnowflakeIdGenerator implements IdentifierGenerator {

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return SnowflakeService.getService().nextId();
    }

}
